<?php

namespace App\Model;

use PhalApi\Model\NotORMModel as NotORM;


class GoodsType extends NotORM
{
    public function getGoodsTypes()
    {
        return $this->getORM()->fetchAll();
    }

    public function updateGoodsTypeInfo($goodType_name, $level, $goodType_parentName, $goodType_id)
    {
        $data = array('name' => $goodType_name, 'level' => $level, 'parentName' => $goodType_parentName);
        return $this->getORM()->where('id', $goodType_id)->update($data);
    }

    public function insertGoodsTypeInfo($goodType_name, $goodType_parentName)
    {

        $data = array('name' => $goodType_name, 'level' => 1, 'parentName' => $goodType_parentName, 'flag' => 1);
        // INSERT INTO tbl_user (name, age, note) VALUES ('PhalApi', 1, 'framework')
        $orm = $this->getORM();
        $orm->insert($data);
        return $orm->insert_id();
//        $sql = "INSERT  INTO t_goodstype (`name`, `level`, `parentName`, `flag`) VALUES ('$goodType_name', '$level','$goodType_parentName',1 );";
//        return $this->executeSql($sql);
    }

    public function deleteGoodsTypeInfo($goodType_id)
    {
        return $this->getORM()->where('id', $goodType_id)->delete();
    }

    public function likeQueryByGoodsTypeLevel($like_goodTypeLevel)
    {
        return $this->getORM()->where('level LIKE ?', "%$like_goodTypeLevel%")->fetchAll();

    }

    public function likeQueryByGoodsTypeName($like_goodTypeName)
    {
        return $this->getORM()->where('name LIKE ?', "%$like_goodTypeName%")->fetchAll();

    }
}